package org.seven.jrdp.web.t;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.seven.jrdp.biz.t.model.THt;
import org.seven.jrdp.biz.t.service.THtService;
import org.seven.jrdp.commons.model.Option;
import org.seven.jrdp.commons.model.Result;
import org.seven.jrdp.commons.mybatis.model.PageRequest;
import org.seven.jrdp.commons.util.ServletUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageInfo;

@RestController
@RequestMapping("/mgt/t/ht")
public class THtController {
	@Autowired
	private THtService tHtService;

	@GetMapping("/{view}")
	public ModelAndView view(@PathVariable String view) {
		return new ModelAndView("mgt/t/ht/ht_" + view);
	}

	@PostMapping("/find")
	public PageInfo<THt> find(PageRequest pageRequest, HttpServletRequest request) {
		Map<String, Object> map = ServletUtils.getSearchParams(request);
		PageInfo<THt> page = tHtService.find(map, pageRequest);
		return page;
	}

	@RequestMapping("/get")
	public THt get(String id) {
		THt tHt = tHtService.get(id);
		return tHt;
	}

	@PostMapping("/insert")
	public Result insert(THt tHt) {
		tHtService.insert(tHt);
		return Result.SUCCESS;
	}

	@PostMapping("/update")
	public Result update(THt tHt) {
		tHtService.update(tHt);
		return Result.SUCCESS;
	}

	@PostMapping("/delete")
	public Result delete(String id) {
		tHtService.delete(id);
		return Result.SUCCESS;
	}

	@RequestMapping("/option")
	public List<Option> option() {
		return tHtService.getOption();
	}
}